<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
     如果给数列先排个序 所谓的全局倒置就是 元素偏离正确位置 >= 1 
     所谓的局部倒置就是 元素偏离正确位置 == 1
    所以如果全局倒置和局部倒置相等，只能 元素偏离正确位置 == 1
    */
    var isIdealPermutation = function (A) {
      return A.every((n, index) => Math.abs(n - index) <= 1)
    };
    console.log(isIdealPermutation(A = [1, 0, 2]))
  </script>
</body>

</html>